package ass.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ass.beans.UserBean;
import ass.dao.UserDAO;
import ass.dao.support.UserDAOImpl;

/**
 * Servlet implementation class FriendSearch
 */
public class FriendSearch extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FriendSearch() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String firstName = (String) request.getParameter("firstname");
		String lastName = (String) request.getParameter("lastname");
		String email = (String) request.getParameter("email");
		
		UserDAO userDAO = new UserDAOImpl();
		
		List<UserBean> userBeanList = userDAO.getSearchedUser(firstName, lastName, email);
//		
//		response.setContentType("text/html");// from response, set content type
//		PrintWriter out = response.getWriter();// from response, get output writer
//		
		request.setAttribute("userList", userBeanList);
		String nextJSP = "";
		nextJSP = "/userFrdSearchResult.jsp";
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
		dispatcher.forward(request, response);
		
//		for (UserBean userBean : userBeanList){
//			out.println(userBean.getFirst_name() + "<br>");
//			out.println(userBean.getLast_name() + "<br>");
//			out.println(userBean.getEmail() + "<br>");
//			out.println("<br>");
//		}
//		
//		out.close();
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
